﻿#include <qg/qg.h>

int main(void)
{
	k_mesg("FREETYPE FONT TEST\n");

	qgDevice* dev = qgDevice::New(NULL, 640, 480, QGSDF_MSAA | QGSDF_LAYOUT);

	if (dev)
	{
		qgStub* stub = dev->GetStub();
		qgFreeType* font = qgFreeType::New();

		//
		float x = 0.0f, y = 0.0f;

		while (dev->Run())
		{
			float spd = 200.0f * stub->GetAdvance();
			const tpl::Point& size = stub->GetSize();

			if (stub->IsKeyDown(QIK_UP)) y -= spd;
			if (stub->IsKeyDown(QIK_DOWN)) y += spd;
			if (stub->IsKeyDown(QIK_LEFT)) x -= spd;
			if (stub->IsKeyDown(QIK_RIGHT)) x += spd;

			//
			tpl::BlueStr<260> bs;
			bs.Format("[%.2f]", stub->GetRunFps());

			tpl::Point pt;
			font->SetSize(24);
			font->CalcPoint(&pt, 0, bs.Data(), bs.Length());

			x = k_clamp(x, 0.0f, (float)(size.x - pt.x));
			y = k_clamp(y, 0.0f, (float)(size.y - pt.y));

			//
			dev->Enter();

			font->SetSize(24);
			font->Write((int)x, (int)y, 0, bs.Data());

			font->SetSize(16);
			font->Write(5, 30, 0, "Test~~!!! \xED\x95\x9C\xEA\xB8\x80 \xE6\xBC\xA2\xE5\xAD\x97 \xEC\x9A\xB0\xEC\x99\x95\xE3\x85\x8B\xEA\xB5\xBF\xE3\x85\x8B~!");

			font->SetSize(32);
			font->WriteL(5, 50, 0, L"UNICODE,유니코드,ユニコード,萬國碼,mã đơn nhất,Юникод,Уникод,یونی‌کد,يونيكود");

			dev->Leave();
			dev->Flush();
		}

		font->Unload();
		dev->Unload();
	}

	return 0;
}

